#include<iostream>
#include<jsoncpp/json/json.h>
#include<string>
#include<jsoncpp/json/value.h>
using namespace std;

std::string seria(Json::Value& val)
{
  val["学号"] = 1001;
  val["姓名"] = "张三";
  val["婚姻状况"] = false;
  val["成绩"].append(77);        //val[对象].apped()专用于数组元素添加
  val["成绩"].append(88);
  val["成绩"].append(99);

  Json:: FastWriter writer;
  string str = writer.write(val);
  str[str.size()-1] = '\0';
  return str;
}

void unseria(string& str,Json::Value& val)
{
  Json::Reader reader;
  bool ret = reader.parse(str,val);
  if(ret == false)
  {
    printf("Json::Reader.parse failed\n");
    return;
  }
  cout<<val["学号"].asInt()<<endl;
  cout<<val["姓名"].asString()<<endl;
  cout<<val["姓名"].asCString()<<endl;
  cout<<val["婚姻状况"].asBool()<<endl;
  int num = val["成绩"].size();
  for(int i =0;i<num;i++)
  {
    cout<<val["成绩"][i].asFloat()<<endl;
  }
}

int main()
{
  Json::Value val;
  string str = seria(val);
  cout<<"["<<str<<"]"<<endl;
  unseria(str,val);
  return 0;
}

